package com.tbit.uqbike.service.business.tag.strategy;

import com.tbit.uqbike.enums.TagOperationType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 标签操作策略工厂
 *
 *
 * @author <a href="mailto:chen.chaoxiong@tbit.com.cn">ChenChaoXiong</a>
 * @since 2024/7/12
 */

@Component
public class TagOperationStrategyFactory {

    private final Map<TagOperationType, TagOperationStrategy> strategyMap;

    @Autowired
    public TagOperationStrategyFactory(List<TagOperationStrategy> strategies) {
        this.strategyMap = strategies.stream()
                                     .collect(Collectors.toMap(TagOperationStrategy::getOperationType, Function.identity()));
    }

    public TagOperationStrategy getStrategy(TagOperationType type) {
        return strategyMap.get(type);
    }
}